package com.study.d017methods;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

/**setUserData()方法的使用
*@description
*@author xtayhame
*date 2020年3月15日
*version
*since v1.0
*/
public class SetUserDataMain extends Application{
	public static void main(String[] args) {
		launch(args);
	}
	@Override
	public void start(Stage stage) throws Exception {
		AnchorPane anchorPane = new AnchorPane();

		ToggleGroup group = new ToggleGroup();

		HBox   hBox = new HBox(30);

		RadioButton r1 = new RadioButton("男");
		r1.setUserData("M");
		r1.setToggleGroup(group);

		RadioButton r2 = new RadioButton("女");
		r2.setUserData("F");
		r2.setToggleGroup(group);

		hBox.getChildren().addAll(r1,r2);

		anchorPane.getChildren().addAll(hBox);

		stage.setScene(new Scene(anchorPane, 300, 400));

		stage.show();
		stage.setTitle("setUserData()方法的使用");

		group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {

			@Override
			public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {
				System.out.println("当前选择的是："+newValue.getUserData());
			}
		});
	}
}
